var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var BundleConfig = require("AA_BundleConfig");
var ResKeeper = require("AA_ResKeeper");
var Excel = require("AA_Excel");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var NodePoolMag = require("AA_NodePoolMag");
var UI_MosterLogic = require("AA_UI_MosterLogic");
var UI_BulletCollider = require("AA_UI_BulletCollider");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_Bullet = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.bulletId = 1;
    t.img = null;
    t.attack = 0;
    t.isbaoji = false;
    t.attackfang = null;
    t.attacktype = 1;
    t.isbisha = false;
    t.nowtagMoster = null;
    t.nowdirection = 0;
    t.tuoweiNode = null;
    t.tagMosterX = 0;
    t.tagMosterY = 0;
    t.isshua = false;
    t.offtime = 0;
    t.tuoweiscale = 0;
    t.bulletspeed = 20;
    t.issend = false;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.initBullet = function (e, t) {
    return __awaiter(this, undefined, undefined, function () {
      var o;
      var n;
      var i;
      var a;
      var r;
      return __generator(this, function (c) {
        switch (c.label) {
          case 0:
            this.attack = e.attack;
            this.isshua = false;
            this.attackfang = e.playerId;
            this.attacktype = e.feixintype;
            this.isbaoji = e.isbaoji;
            this.isbisha = e.isbisha;
            this.nowtagMoster = t;
            o = cc.v2();
            cc.Vec2.subtract(o, cc.v2(this.nowtagMoster.x, this.nowtagMoster.y), this.node.getPosition());
            this.nowdirection = Math.atan2(o.y, o.x);
            this.issend = true;
            if (n = Excel.Excel.shuiguobuff(this.attackfang.sgtianfuid)) {
              switch (n.buffefftype) {
                case 10:
                  i = cc.Vec2.distance(cc.v2(this.nowtagMoster.x, this.nowtagMoster.y), this.node.getPosition());
                  a = i / n.value[0] * (n.value[1] / 100);
                  this.attack = this.attack + this.attack * a;
              }
            }
            return [4, this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/player/player" + this.attackfang.playerId + "_1", cc.SpriteFrame)];
          case 1:
            r = c.sent();
            this.img.spriteFrame = r;
            this.createTuoWei();
            return [2];
        }
      });
    });
  };
  _creator.prototype.onDisable = function () {
    if (this.tuoweiNode) {
      NodePoolMag.NodePoolMag.instance.recycleNode("tuowei", this.tuoweiNode);
      this.tuoweiNode = null;
    }
  };
  _creator.prototype.createTuoWei = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      return __generator(this, function (o) {
        switch (o.label) {
          case 0:
            if (e = NodePoolMag.NodePoolMag.instance.getNode("tuowei")) {
              return [3, 2];
            } else {
              return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "prefabs/effpre/UI_TuoWei", cc.Prefab)];
            }
          case 1:
            t = o.sent();
            NodePoolMag.NodePoolMag.instance.createNodeCount("tuowei", 1, t);
            e = NodePoolMag.NodePoolMag.instance.getNode("tuowei");
            o.label = 2;
          case 2:
            this.tuoweiNode = e;
            GameGlobalVariable.GameGlobalVariable.effNode.addChild(e);
            return [2];
        }
      });
    });
  };
  _creator.prototype.getBulletAttack = function (e) {
    var t = this.attack;
    if (e.isjianshu && 14 == this.attackfang.playerId) {
      var o = Excel.Excel.shuiguo(1014);
      t += t * (Excel.Excel.shuiguobuff(o.talent).value[0] / 100);
    }
    if (1 == e.nowmosterdata.boss && 10 == this.attackfang.playerId) {
      o = Excel.Excel.shuiguo(1010);
      t += t * (Excel.Excel.shuiguobuff(o.talent).value[0] / 100);
    }
    return t;
  };
  _creator.prototype.sendBullet1 = function (e) {
    var t = cc.v2();
    if (!this.isshua) {
      this.tagMosterX = this.nowtagMoster.x;
      this.tagMosterY = this.nowtagMoster.y;
    }
    cc.Vec2.subtract(t, cc.v2(this.tagMosterX, this.tagMosterY), this.node.getPosition());
    this.nowdirection = Math.atan2(t.y, t.x);
    this.moveBullet(this.nowdirection, e);
  };
  _creator.prototype.moveBullet = function (e, t) {
    this.node.x += Math.cos(e) * this.bulletspeed;
    this.node.y += Math.sin(e) * this.bulletspeed;
    this.node.angle = e * (180 / Math.PI) - 180;
    this.nowtagMoster.getComponent(UI_MosterLogic.default).isDie && (this.isshua = true);
    var o = cc.Vec2.distance(cc.v2(this.nowtagMoster.x, this.nowtagMoster.y), this.node.getPosition());
    this.offtime += t;
    o <= 25 && this.img.node.getComponent(UI_BulletCollider.default).onYouHuaPeng(this.nowtagMoster);
    if (this.isshua) {
      var n = cc.Vec2.distance(cc.v2(this.nowtagMoster.x, this.nowtagMoster.y), this.node.getPosition());
      this.offtime += t;
      n <= 50 && this.hideBullet();
      if (this.offtime >= .5) {
        this.offtime = 0;
        this.hideBullet();
      }
    }
  };
  _creator.prototype.hideBullet = function () {
    this.issend = false;
    NodePoolMag.NodePoolMag.instance.recycleNode("bullet_" + this.bulletId, this.node);
  };
  _creator.prototype.getNowMosterNode = function (e) {
    var t = this.attackfang.mosterNodes.children;
    var o = [];
    for (var n = 0; n < t.length; n++) {
      var i = t[n];
      var a = cc.Vec2.distance(i.getPosition(), this.node.getPosition());
      (a -= i.width / 2 + this.node.width / 2) <= e && o.push(i);
    }
    return o;
  };
  _creator.prototype.sendBullet2 = function () { };
  _creator.prototype.getBulletSpeed = function () {
    this.bulletspeed = this.bulletspeed * GameGlobalVariable.GameGlobalVariable.jiasuState;
    return this.bulletspeed;
  };
  _creator.prototype.getBiSha = function () {
    return this.isbisha;
  };
  _creator.prototype.onUpdate = function (e) {
    if (this.issend) {
      this.sendBullet1(e);
      if (this.tuoweiNode) {
        this.tuoweiNode.x = this.node.x;
        this.tuoweiNode.y = this.node.y;
      }
    }
  };
  __decorate([_property()], _creator.prototype, "bulletId", undefined);
  __decorate([_property(cc.Sprite)], _creator.prototype, "img", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_UI_Bullet;